package com.briup.corejava.day21;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.List;

/**
 * 接收对象的tcp服务器
 */
public class TcpServerObject {
    public static void main(String[] args) {
        ServerSocket serverSocket = null;
        Socket socket = null;
        ObjectInputStream ois = null;
        try {
            serverSocket = new ServerSocket(8888);
            socket = serverSocket.accept();
            ois = new ObjectInputStream(socket.getInputStream());
            // 读取对象
            Object o = ois.readObject();
            // 学生完成：将o安全转换为List<User>对象
            List<User> list = (List<User>) o;
            // 遍历的新方法
            list.forEach(System.out::println);

        } catch (IOException e) {
            throw new RuntimeException(e);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }

    }
}
